/** 
 * Copyright 2010 Erlacher Felix, Estgfaeller Wolfgang, Ferula Patrick
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package at.socialconference.app;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import at.socialconference.app.model.AConference;
import at.socialconference.app.model.ATalk;

public class TalkListActivity extends ListActivity{


	private ArrayList<ATalk> talks;

	public String[] getListItems(AConference conference){
		if(conference!=null){
			 talks = conference.getATalks();
			if(talks!=null){
				String[] si = new String[talks.size()];
				for(int i=0;i<talks.size();i++){
					ATalk t = talks.get(i);
					
					SimpleDateFormat sdf = new SimpleDateFormat("dd.MM HH:mm");
					
					String tmp = t.getDate()!=null?sdf.format(t.getDate()):"";
					tmp += "\n";
					tmp += t.getTitle()!=null?t.getTitle():"";
					si[i]= tmp;
				}
				return si;
			}
		}
		return new String[0];
	}
	

	public void onCreate(Bundle savedInstanceState) {
		Bundle b = getIntent().getExtras();
		AConference u = (AConference)b.getParcelable("conference");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listview);
		ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, getListItems(u));
		this.setListAdapter(arrayAdapter);
		
	}
	
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		ATalk talk = talks.get(position);
		Bundle b = new Bundle();
		b.putParcelable("talk", talk); 
		Intent i = new Intent(this, TalkTabActivity.class); 
		i.putExtras(b);
		startActivity(i);
	}
}
